﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>安全认证服务平台-登录</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css?t=@DateTimeOffset.Now.ToUnixTimeSeconds()" />
    <link rel="stylesheet" href="/admin/css/other/login.css?t=@DateTimeOffset.Now.ToUnixTimeSeconds()" />
    <link rel="stylesheet" href="/admin/css/variables.css?t=@DateTimeOffset.Now.ToUnixTimeSeconds()" />
    <script>if (window.self != window.top) { top.location.reload(); }</script>
</head>

<body>
    <div class="login-page" style="background-image: url(/admin/images/background.svg)">
        <div class="layui-row">
            <div class="layui-col-sm6 login-bg layui-hide-xs">
                <img class="login-bg-img" src="/admin/images/banner.png" alt="" />
            </div>
            <div class="layui-col-sm6 layui-col-xs12 login-form">
                <div class="layui-form">
                    <div class="form-center">
                        <div class="form-center-box">
                            <div class="top-log-title">
                                <img class="top-log" src="/admin/images/logo.png" alt="" />
                                <span>LayUiAdmin.Net</span>
                            </div>
                            <div class="top-desc">
                                致 力 于 让 " Web " 开 发 变 得 简 单 优 雅
                            </div>
                            <div style="margin-top: 30px;">
                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-username"></i>
                                        </div>
                                        <input id="account" name="account" lay-verify="required" placeholder="账户" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-password"></i>
                                        </div>
                                        <input type="password" id="password" name="password"
                                               lay-verify="required|confirmPassword" placeholder="密码" autocomplete="off"
                                               class="layui-input" lay-affix="eye">
                                    </div>
                                </div>
                                <div class="tab-log-verification">
                                    <div class="verification-text">
                                        <div class="layui-input-wrap">
                                            <div class="layui-input-prefix">
                                                <i class="layui-icon layui-icon-auz"></i>
                                            </div>                                            
                                            <input id="code" name="code" lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <img id="code_img" src="/admin/images/captcha.gif" alt="" class="verification-img" />
                                    <input type="hidden" id="codeId" name="codeId" />
                                </div>
                                <div class="layui-form-item">
                                    <div class="remember-passsword">
                                        <div class="remember-cehcked">
                                            <input type="checkbox" name="like1[write]" lay-skin="primary" title="自动登录">
                                        </div>
                                    </div>
                                </div>
                                <div class="login-btn">
                                    <button type="button" lay-submit lay-filter="login" class="layui-btn login">登 录</button>
                                </div>
                                <div class="other-login">
                                    <div class="other-login-methods">
                                        Copyright © 2021-2024 景畔科技
                                    </div>
                                    <div class="greenText">版本：V2.0</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/component/layui/layui.js?t=@DateTimeOffset.Now.ToUnixTimeSeconds()"></script>
    <script src="~/component/pear/pear.js?t=@DateTimeOffset.Now.ToUnixTimeSeconds()"></script>
    <script src="~/component/libs/sm2.js"></script>
    <script>
        layui.use(['button', 'popup', 'http'], function () {
            var $ = layui.$;
            var form = layui.form;
            var button = layui.button;
            var popup = layui.popup;
            var http = layui.http;           

            //
            window.loadCaptcha = function () {
                http.get('/api/sysAuth/captcha').then(function (res) {
                    $('#codeId').val(res.result.id);
                    $('#code_img').attr('src', 'data:image/jpeg;base64,' + res.result.img).click(loadCaptcha);
                })
            }
            loadCaptcha();

            // 登录提交
            form.on('submit(login)', function (data) {
                var publicKey = `0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312`;
                data.field.password = sm2.doEncrypt(data.field.password, publicKey, 1);              
                http.post('/api/sysAuth/login', data.field).then((res) => {
                    if (res.code==200) {
                        http.setAuthorizationToken(res.result.accessToken)
                        button.load({
                            elem: '.login',
                            time: 500,
                            done: function () {
                                popup.success("登录成功。", function () {
                                    location.href = "/admin/index"
                                });
                            }
                        })
                    }
                    else {
                        loadCaptcha();
                        popup.failure(res.message)
                    }
                });

                return false;
            });
        })
    </script>
</body>

</html>
